//
// UIScrollView+SVPullToRefresh.h
//
// Created by Sam Vermette on 23.04.12.
// Copyright (c) 2012 samvermette.com. All rights reserved.
//
// https://github.com/samvermette/SVPullToRefresh
//
// Modified by https://github.com/harpher/SVPullToRefresh 12.03.13

#import <UIKit/UIKit.h>
#import <AvailabilityMacros.h>

typedef void (^SVPullToRefreshActionHandler)(BOOL byUser);
typedef UIEdgeInsets (^SVPullToRefreshExpectedContentInsetGetter)();

@class SVPullToRefreshView;

@interface UIScrollView (SVPullToRefresh)

- (void)addPullToRefreshWithActionHandler:(SVPullToRefreshActionHandler)actionHandler
  expectedContentInsetGetterInNormalState:(SVPullToRefreshExpectedContentInsetGetter)expectedContentInsetGetterInNormalState
                               viewHeight:(CGFloat)height
                           verticalOffset:(CGFloat)verticalOffset;

- (void)clearAllPullToRefreshIssues;
- (void)triggerPullToRefresh;

@property (nonatomic, strong, readonly) SVPullToRefreshView *pullToRefreshView;
@property (nonatomic, assign) BOOL showsPullToRefresh;

@end


enum {
    SVPullToRefreshStateStopped = 0,
    SVPullToRefreshStateTriggered,
    SVPullToRefreshStateLoading,
    SVPullToRefreshStateAll = 10
};

typedef NSUInteger SVPullToRefreshState;

@protocol SVPullToRefreshDelegate <NSObject>

@optional
- (void)pullToRefreshView:(SVPullToRefreshView *)pullToRefreshView
          stateDidChanged:(SVPullToRefreshState)state from:(SVPullToRefreshState)previousState;

// @param percent, > 0, and can > 1.0 if over pulling
- (void)pullToRefreshView:(SVPullToRefreshView *)pullToRefreshView percentToLoading:(CGFloat)percent;

@end

@interface SVPullToRefreshView : UIView

@property (nonatomic, strong) UIColor *arrowColor;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong, readonly) UILabel *titleLabel;
@property (nonatomic, strong, readonly) UILabel *subtitleLabel;
@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;

@property (nonatomic, readonly) CGFloat originalTopInset; // MUST readonly
@property (nonatomic, assign) CGFloat triggerHeight;
@property (nonatomic, assign) CGFloat verticalOffset; // position
@property (nonatomic, readwrite) CGFloat loadingHeight;

@property (nonatomic, readonly) CGFloat percentForPullToRefresh;
@property (nonatomic, readonly) SVPullToRefreshState state;
@property (nonatomic, readonly) SVPullToRefreshState previousState;

- (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state;
- (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state;

@property (nonatomic, strong) UIView <SVPullToRefreshDelegate> *customView;

- (BOOL)isAnimating;
- (void)startAnimating;
- (void)stopAnimating;

// deprecated; use setSubtitle:forState: instead
@property (nonatomic, strong, readonly) UILabel *dateLabel DEPRECATED_ATTRIBUTE;
@property (nonatomic, strong) NSDate *lastUpdatedDate DEPRECATED_ATTRIBUTE;
@property (nonatomic, strong) NSDateFormatter *dateFormatter DEPRECATED_ATTRIBUTE;

// deprecated; use [self.scrollView triggerPullToRefresh] instead
- (void)triggerRefresh DEPRECATED_ATTRIBUTE;

@end
